<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="证书类别">
              <j-search-select-tag placeholder="请选择证书类别" v-model="queryParam.certNo" dict="certificate_type" @change="getCertificateName"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="证书名称">
              <a-select
                :getPopupContainer="(node) => node.parentNode"
                showSearch
                placeholder="请选择证书名称"
                style="width: 100%"
                :filterOption="filterOption"
                v-model="cerName"
                @change="changeName"
                allowClear
              >
                <a-select-option v-for="d in dataOptions" :key="d.id" :value="d.id">{{ d.certName }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="证书字段">
              <a-input placeholder="请输入证书字段" v-model="queryParam.certField"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="newSearchResets" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAddOther('')" type="primary" icon="plus">证书类别</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('公司档案')" :disabled="isDisabledAuth('erpCompanyFiles:export')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpCompanyFiles:import')">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpCompanyFiles:delete')"><a-icon type="delete"/>删除</a-menu-item>
          <a-menu-item key="2" @click="batchSubmit" :disabled="isDisabledAuth('erpCompanyFiles:submit')"><a-icon type="to-top" />提交</a-menu-item>
          <a-menu-item key="3" @click="batchAudit" :disabled="isDisabledAuth('erpCompanyFiles:audit')"><a-icon type="audit"/>审核</a-menu-item>
          <a-menu-item key="4" @click="batchCounterTrial" :disabled="isDisabledAuth('erpCompanyFiles:counterTrial')"><a-icon type="rollback" />反审</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: scrollX }"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a-button
            class="ruleButton"
            :ghost="true"
            type="primary"
            icon="edit"
            @click="handleEditOther(record)"
            :disabled="isDisabledAuth('erpCompanyFiles:edit')"
          />
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="delete"
              :disabled="isDisabledAuth('erpCompanyFiles:delete')"
            />
          </a-popconfirm>
          <a-divider type="vertical" v-if="record.billNo.substring(0,4)=='ZSMC' || record.billNo.substring(0,4)=='ZSLB'"/>
          <a v-if="record.billNo.substring(0,4)=='ZSLB'" @click="handleAddOther(record)">添加证书名称</a>
          <a v-if="record.billNo.substring(0,4)=='ZSMC'" @click="handleAddOther(record)">添加证书字段</a>
        </span>
      </a-table>
    </div>

    <ErpCertificateBasicFieldsModal ref="modalForm" @ok="modalFormOk"></ErpCertificateBasicFieldsModal>
    <audit-modal ref="auditModal" @ok="modalFormOk"></audit-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpCertificateBasicFieldsModal from './modules/ErpCertificateBasicFieldsModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
import { getAction } from '@/api/manage'
export default {
  name: 'ErpCertificateBasicFieldsList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpCertificateBasicFieldsModal,
  },
  data() {
    return {
      description: '证书基础字段页面',
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '单据编号',
          align: 'center',
          width: 300,
          dataIndex: 'billNo',
          ellipsis: true,
        },
        {
          title: '证书类别',
          align: 'center',
          width: 200,
          dataIndex: 'certNo',
          customRender: (text, r) => {
            if (!text) {
              return ''
            } else {
              return filterMultiDictText(this.dictOptions['certNo'], text + '')
            }
          },
          ellipsis: true,
        },
        {
          title: '证书名称',
          align: 'center',
          width: 300,
          dataIndex: 'certName',
          ellipsis: true,
        },
        {
          title: '证书字段',
          align: 'center',
          width: 300,
          dataIndex: 'certField',
          ellipsis: true,
        },
        {
          title: '备注',
          align: 'center',
          width: 300,
          dataIndex: 'remark',
          ellipsis: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 200,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action',
          },
        },
      ],
      url: {
        list: '/api/erp/basecertinfo/field/searchList',
        delete: '/api/erp/basecertinfo/field/delete',
      },
      dictOptions: {},
      superFieldList: [],
      dataOptions: [],
      ipagination: {
        current: 1,
        pageSize: -1,
      },
      cerName: undefined
    }
  },
  created() {
    this.getSuperFieldList()
    this.getCertificateName('')
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    newSearchResets(){
      this.onClearSelected();
      this.queryParam = {}
      this.cerName = undefined
      this.loadData(1)
      this.getCertificateName('')
    },
    changeName(val){
      if(val){
        this.$set(this.queryParam,'certName',this.dataOptions.filter(v => v.id==val)[0].certName)
      } else {
        this.$set(this.queryParam,'certName','')
      }
    },
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    async getCertificateName(typeCode){
      this.$set(this.queryParam,'certName',undefined)
      this.cerName = undefined
      let res = await getAction('/api/erp/basecertinfo/field/nameList',{ typeCode })
      if(res.success){
        this.dataOptions = res.result || []
      }
    },
    initDictConfig() {
      initDictOptions('certificate_type').then(async(res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'certNo', res.result)
        }
      })
      // initDictOptions('certificate_name').then(async(res) => {
      //   if (res.success) {
      //     this.$set(this.dictOptions, 'certName', res.result)
      //   }
      // })
    },
    handleEditOther (record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
    },
    handleAddOther (record) {
      this.$refs.modalForm.add(record)
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'fileName', text: '公司名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'enterpriseCreditCode', text: '统一社会信用代码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'legalRepresentative', text: '公司法人', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'registerCapital', text: '注册资本（万元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'enterpriseAddress', text: '公司地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'liaison', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'liaisonMobile', text: '联系电话', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bankName', text: '开户行', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bankAccountNo', text: '银行账号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'proposer', text: '创建人', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'bussiness', text: '经营范围', dictCode: '' })
      fieldList.push({ type: 'string', value: 'auditStatus', text: '审核状态', dictCode: 'audit_status' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
